package com.lovo.config;

//import com.lovo.interceptor.InvoiceInterceptor;
//import com.lovo.interceptor.UserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
//@EnableWebMvc springMVC已经自带了
public class WebConfig extends WebMvcConfigurationSupport {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");

        // 解决swagger无法访问
        registry.addResourceHandler("/swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        // 解决swagger的js文件无法访问
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:d:/server/upload/");
    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry){
//        String [] addPathPatterns={"/**"};
//        String [] excludePathPatterns={"/static/**"};
//        registry.addInterceptor(new UserInterceptor())
//                .addPathPatterns(addPathPatterns)
//                .excludePathPatterns(excludePathPatterns);
//
//        registry.addInterceptor(new InvoiceInterceptor())
//                .addPathPatterns(addPathPatterns);
//    }
}
